package com.hzw.service.impl;

import com.hzw.bean.ArticleTag;
import com.hzw.dao.ArticleTagMapper;
import com.hzw.service.ArticleTagService;
import com.hzw.utils.UUIDUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/3/28.
 */
@Service
public class ArticleTagServiceImpl implements ArticleTagService {
    @Resource
    private ArticleTagMapper articleTagMapper;

    /**
     * 新增标签
     * @param articleTag
     */
    @Override
    public void addArticleTag(ArticleTag articleTag) {
        String id = UUIDUtils.getUUID();
        articleTag.setId(id);
        articleTagMapper.insertSelective(articleTag);
    }

    /**
     * 通过Id删除文章标签(软删除)
     * @param tagId
     * @return
     */
    @Override
    public int deleteArticleTagById(String tagId) {
        return articleTagMapper.deleteArticleByTagId(tagId);
    }

    /**
     * 更新文章标签:只更新非空字段
     * @param articleTag
     * @return
     */
    @Override
    public int updateArticleTagById(ArticleTag articleTag) {
        return articleTagMapper.updateByPrimaryKeySelective(articleTag);
    }


    /**
     * 根据Id查找文章标签
     * @param tagId
     * @return
     */
    @Override
    public ArticleTag selectArticleTagById(String tagId) {
        return articleTagMapper.selectArticleTagById(tagId);
    }

    /**
     * 查找所有的文章标签
     * @return
     */
    @Override
    public List<ArticleTag> selectAllArticleTag() {
        return articleTagMapper.selectAllArticleTag();
    }

    /**
     * 判断type是否已存在
     * @param type
     * @return
     */
    @Override
    public int checkExistType(int type) {
        return articleTagMapper.checkExistType(type);
    }
}
